package com.ruoyi.web.controller.control;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.control.domain.BeltHistory;
import com.ruoyi.control.service.IBeltHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 皮带历史Controller
 * 
 * @author ruoyi
 * @date 2024-11-09
 */
@RestController
@RequestMapping("/control/BeltHistory")
public class BeltHistoryController extends BaseController
{
    @Autowired
    private IBeltHistoryService beltHistoryService;

    /**
     * 查询皮带历史列表
     */
    @PreAuthorize("@ss.hasPermi('control:BeltHistory:list')")
    @GetMapping("/list")
    public TableDataInfo list(BeltHistory beltHistory)
    {
        startPage();
        List<BeltHistory> list = beltHistoryService.selectBeltHistoryList(beltHistory);
        return getDataTable(list);
    }

    /**
     * 导出皮带历史列表
     */
    @PreAuthorize("@ss.hasPermi('control:BeltHistory:export')")
    @Log(title = "皮带历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BeltHistory beltHistory)
    {
        List<BeltHistory> list = beltHistoryService.selectBeltHistoryList(beltHistory);
        ExcelUtil<BeltHistory> util = new ExcelUtil<BeltHistory>(BeltHistory.class);
        util.exportExcel(response, list, "皮带历史数据");
    }

    /**
     * 获取皮带历史详细信息
     */
    @PreAuthorize("@ss.hasPermi('control:BeltHistory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(beltHistoryService.selectBeltHistoryById(id));
    }

    /**
     * 新增皮带历史
     */
    @PreAuthorize("@ss.hasPermi('control:BeltHistory:add')")
    @Log(title = "皮带历史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BeltHistory beltHistory)
    {
        return toAjax(beltHistoryService.insertBeltHistory(beltHistory));
    }

    /**
     * 修改皮带历史
     */
    @PreAuthorize("@ss.hasPermi('control:BeltHistory:edit')")
    @Log(title = "皮带历史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BeltHistory beltHistory)
    {
        return toAjax(beltHistoryService.updateBeltHistory(beltHistory));
    }

    /**
     * 删除皮带历史
     */
    @PreAuthorize("@ss.hasPermi('control:BeltHistory:remove')")
    @Log(title = "皮带历史", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(beltHistoryService.deleteBeltHistoryByIds(ids));
    }


    /**
     * 皮带故障次数  1天
     */
    @GetMapping("/getBeltTotal")
    public int getBeltTotal()
    {
        int total = beltHistoryService.getBeltTotal();
        return total;
    }



}
